<template>
    <div>
        <Form
                ref="form"
                :form-items="formItems"
        ></Form>
        <BaiduMapLocationDialog ref="baiduMapLocationDialog" v-on:selectLocation="(location)=>{
        $refs.form.setFormItem('longitude',location.longitude)
        $refs.form.setFormItem('latitude',location.latitude)
        }">
        </BaiduMapLocationDialog>
    </div>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'code'
                        },
                        element:{
                            label: '编号',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '名称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'nameAlias'
                        },
                        element:{
                            label: '名称别名',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'longitude'
                        },
                        element:{
                            label: '经度',
                            type: 'inputButton',
                            inputButton:{
                                bClick:this.longitudeBtnClick
                            },
                        }
                    },
                    {
                        field: {
                            name: 'latitude'
                        },
                        element:{
                            label: '纬度',
                        }
                    },
                    {
                        field: {
                            name: 'belowGroundParkingSpaceNum'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '地下车位数',
                        }
                    },
                    {
                        field: {
                            name: 'buildAt'
                        },
                        element:{
                            type: 'date',
                            date:{
                                type: 'date',
                                valueFormat: 'timestamp'
                            },
                            label: '始建于',
                        }
                    },
                    {
                        field: {
                            name: 'builtAt'
                        },
                        element:{
                            type: 'date',
                            date:{
                                type: 'date',
                                valueFormat: 'timestamp'
                            },
                            label: '建成于',
                        }
                    },
                    {
                        field: {
                            name: 'developerCompanyId'
                        },
                        element:{
                            type: 'selectRemote',
                            selectRemote:{
                                url: this.$baseURL.crm + '/crm/company/listPage',
                            },
                            label: '开发商公司',
                        }
                    },
                    {
                        field: {
                            name: 'propertyCompanyId'
                        },
                        element:{
                            type: 'selectRemote',
                            selectRemote:{
                                url: this.$baseURL.crm + '/crm/company/listPage',
                            },
                            label: '物业公司',
                        }
                    },
                    {
                        field: {
                            name: 'estateId',
                            value: this.$route.query.estateId || null,
                            estateId__label: this.$route.query.estateName || null,
                        },
                        element:{
                            label: '楼盘',
                            type: 'selectRemote',
                            selectRemote:{
                                url: this.$baseURL.house + '/house/estate/listPage',
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'estatePhaseId'
                        },
                        element:{
                            label: '楼盘分期',
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.estateId) {
                                        return null
                                    }
                                    return this.$baseURL.house + '/house/estatephase/list?estateId=' + form.estateId
                                }
                            }
                        }
                    },
                    {
                        field: {
                            name: 'floorNum'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '总层数',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'unitNum'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '单元数',
                        }
                    },
                    {
                        field: {
                            name: 'roomNum'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '总套数',
                        }
                    },
                    {
                        field: {
                            name: 'presaleEstateLicenceId'
                        },
                        element:{
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.estateId) {
                                        return null
                                    }
                                    return this.$baseURL.house + '/house/estatelicence/list?permitTypeDictCode=estate_licence_presale&estateId=' + form.estateId
                                }
                            },
                            label: '预售许可证',
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'post',
                                    url: this.$baseURL.house + '/house/building',
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        methods:{
            longitudeBtnClick () {
                let form =this.$refs.form.getFormData()
                this.$refs.baiduMapLocationDialog.show(form.longitude,form.latitude)

            },
        }
    }
</script>

<style scoped>

</style>